AddManagerWindow = function(){
	var this_window = this;
	
	var validatePassword = function(){
		var pwd = form.pwdFieldset.pwd.getValue();
		var rep = form.pwdFieldset.rep.getValue();
		if(pwd !== rep){
			notice_result_info("两次密码输入不一致");
			return false;
		}
		return true;
	};
	
	var save = function(){
		if(!form.form.isValid()){
			return false;
		}
		
		if(!form.pwdFieldset.collapsed){
			if(!validatePassword()){
				return false;
			}
		}
		
		var params = form.form.getFieldValues();
		if(params["manager.password"]===undefined){
			params["manager.password"] = MD5("admin");
		}else{
			params["manager.password"] = MD5(params["manager.password"]);
		}
		Ajax({
			url : "manager/save.action",
			params : params,
			maskTarget : this_window,
			window : this_window,
			grid : managerPanel
		});
	}
	
	this.listeners = {
			hide : function(){
				form.form.reset();
				form.pwdFieldset.collapse();
			}
		};
	
	var form = new Ext.form.FormPanel({
		frame : true,
		padding : 5,
		labelAlign : "right",
		labelWidth : 60,
		defaults : {
			labelAlign : "right",
			labelWidth : 60,
			defaults : {
				xtype : 'textfield',
				anchor : "95%",
				allowBlank : false
			}
		},
		items : [{
			xtype : 'fieldset',
			title : "账号信息",
			items : [{
				fieldLabel : "账号名",
				name : "manager.name",
				regex : /^\w+$/,
				regexText : "帐号名使用字母，数字及下划线_"
			},{
				xtype : "combo",
				fieldLabel : "权限",
				name : "manager.purview",
				editable : false,
				typeAhead: true,
			    triggerAction: 'all',
			    lazyRender:true,
			    forceSelection : true,
			    mode: 'local',
			    store: new Ext.data.ArrayStore({
			        fields: ["value","text"],
			        data : [[2,"超级管理员"],[1,"管理员"]]
			    }),
			    valueField: "value",
			    displayField: "text"
			}
//			,{
//				fieldLabel : "对应员工",
//				name : "manager.person"
//			}
			]
		},{
			xtype : 'fieldset',
			html : "<font color='blue'>可不设置密码，默认密码为admin，创建后请尽快修改。如需设置密码，请打开[密码设置]</font>"
		},{
			ref : "pwdFieldset",
			xtype : "fieldset",
			title : "密码设置",
			collapsible: true,
			collapsed : true,
			items : [{
				ref : "pwd",
				fieldLabel : "输入密码",
				inputType : "password",
				minLength : 5,
				maxLength : 12,
				name : "manager.password"
			},{
				ref : "rep",
				fieldLabel : "确认密码",
				minLength : 5,
				maxLength : 12,
				inputType : "password"
			}],
			listeners : {
				collapse : function(){
					this.pwd.disable();
					this.rep.disable();
				},
				expand : function(){
					this.pwd.enable();
					this.rep.enable();
				}
			}
		}]
	});
	
	
	AddManagerWindow.superclass.constructor.call(this, {
		title : "创建管理员账号",
		iconCls : "user_add",
		width : 350,
		shadow : false,
		border : false,
		autoHeight : true,
		closeAction : "hide",
		modal : true,
		items : [form],
		buttons : [{
			text : "保存",
			handler : save
		},{
			text : "取消",
			handler : function(){
				this_window.hide();
			}
		}]
	});
};
Ext.extend(AddManagerWindow, Ext.Window);
var addManagerWindow = new AddManagerWindow();